package com.hanbang.maige.pressenter;

import com.hanbang.maige.code.base.presenter.BasePresenter;
import com.hanbang.maige.code.base.view.iview.BaseView;
import com.hanbang.maige.code.base.view.iview.IUpdataUIView;
import com.hanbang.maige.mode.HttpRequest;
import com.hanbang.maige.mode.httpresponse.BaseHttpResponse;
import com.hanbang.maige.utils.http.httpquest.HttpCallBack;
import com.hanbang.maige.utils.http.httpquest.HttpRequestParam;

/**
 * 作者　　: 李坤
 * 创建时间:2016/9/19　17:05
 * 邮箱　　：496546144@qq.com
 * <p>
 * 功能介绍：
 */

public class PublicPresenter<V extends BaseView> extends BasePresenter<V> {

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/11/1 17:29
     * <p>
     * 方法功能：点赞	AddDianzan	bankuai:版块(1-朋友圈)
     * dzTableID:点赞主键
     */

    public void dianzhan(int dzTableID, final int postion) {
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setHint("点赞中");
        HttpCallBack<BaseHttpResponse> callBack = new HttpCallBack<BaseHttpResponse>(buider) {
            @Override
            public void onSuccess(BaseHttpResponse result) {
                super.onSuccess(result);


                if (result.isSucceed()) {
                    mvpView.showInfoSnackbar(result.getMsg());
                    if (mvpView instanceof IUpdataUIView) {
                        ((IUpdataUIView) mvpView).updataUI(postion);
                    }
                } else {
                    mvpView.showErrorSnackbar(result.getMsg());
                }
            }
        };

        HttpRequestParam param = new HttpRequestParam("AddDianzan");
        param.addParam("bankuai", 1);
        param.addParam("dzTableID", dzTableID);
        mvpView.addSubscription(HttpRequest.executeGet(callBack, param));

    }

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/11/1 17:29
     * <p>
     * 方法功能：评论	AddPinglun	bankuai:版块(1-朋友圈)
     * plTableID:评论表主键
     * plUserIdShou:接收者ID（没的话不用传）
     * SendContent:发送内容
     * <p>
     * moniaoId <= 0:一级评论
     * 其他就是二级回复
     */

    public void pinglun(int plTableID, String sendContent, int moniaoId, final int postion) {
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setHint("评论中");
        HttpCallBack<BaseHttpResponse> callBack = new HttpCallBack<BaseHttpResponse>(buider) {
            @Override
            public void onSuccess(BaseHttpResponse result) {
                super.onSuccess(result);


                if (result.isSucceed()) {
                    mvpView.showInfoSnackbar(result.getMsg());
                    if (mvpView instanceof IUpdataUIView) {
                        ((IUpdataUIView) mvpView).updataUI(postion);
                    }
                } else {
                    mvpView.showErrorSnackbar(result.getMsg());
                }
            }
        };

        HttpRequestParam param = new HttpRequestParam("AddPinglun");
        param.addParam("bankuai", 1);
        param.addParam("plTableID", plTableID);
        param.addParam("sendContent", sendContent);
        if (moniaoId > 0) {
            param.addParam("plUserIdShou", moniaoId);
        }
        mvpView.addSubscription(HttpRequest.executeGet(callBack, param));

    }

}
